 var mongodb = require('mongodb');
 var host = 'localhost';
 var port = 27017;
 var dbname = 'docmanage';
 var connect = false;
 exports.connect = function(){
	var server = new mongodb.Server(host,port,{auto_reconnect:true});
	var db = new mongodb.Db(dbname,server,{safe:true});
	db.open(function(err,db){
		if(!err){   
			console.log('connect');
			connect = true;
		}else{
			console.log(err);
		}   
	});
 };
 exports.find = function(name){
	if(connect){
		db.createCollection(name,function(err,collection){
            if(err){
               console.log(err);
           }   
       }); 
	   return collection.find().toArray(function(err,docs){
			if(err){
				console.log(err);
			}
	   });
	}
	return [];
 };
 exports.add = function(strname){
	if(connect){
		db.createCollection(name,function(err,collection){
            if(err){
               console.log(err);
           }   
       }); 
	   var tmp = {name:strname};
		collection.insert(tmp,{safe:true},function(err,result){
			console.log(result);
		}); 
	}
 }
 